<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台欢迎页</title>

    <link rel="stylesheet" href="__PUBLIC__css/bootstrap.css" />
    <link rel="stylesheet" href="__PUBLIC__css/reset.css" />
    <link rel="stylesheet" href="__PUBLIC__css/content.css" />
    <script src="__PUBLIC__js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <style>
        td{
            vertical-align :middle;
        }
        body{
            background-color: #EFF3F6;
        }
    </style>
    <script type="text/javascript">

        function confirmd() {
            var msg = "您真的确定要删除吗?";
            if(confirm(msg)==true){
                return true;
            }else{
                return false;
            }
        }

        function edit(pos_id) {
            //替换名称和描述
            $("#name_"+pos_id).html("<input type='text' name='pos_name_"+pos_id+"' id='pos_name_"+pos_id+"' placeholder='输入新的名称' value='' style='width: 80%' required>");
            $("#des_"+pos_id).html("<input type='text' name='pos_des_"+pos_id+"' id='pos_des_"+pos_id+"' placeholder='输入新的推荐位描述' value='' style='width: 80%' required>");
            $("#but_"+pos_id).html("<input type='button' name='pos_but_"+pos_id+"' id='pos_but_"+pos_id+"' onclick='edit_ajax("+pos_id+")' value='提交' style='width: 80%' required>");
        }

        function edit_ajax(pos_id) {
            var pos_name = $("#pos_name_"+pos_id).val();
            var pos_des = $("#pos_des_"+pos_id).val();
            $.ajax({
                type: 'POST',
                url: "{:url('admin/Position/positionEdit')}",
                data: {
                    pos_name: pos_name,
                    pos_description: pos_des,
                    pos_id: pos_id
                },
                dataType: 'html',
                success: function(data) {
                    if (1 == data) {
                        alert('修改成功!');
                        $("#name_" + pos_id).html(pos_name);
                        $("#des_" + pos_id).html(pos_des);
                        window.location.reload();
                        //$("#but_" + pos_id).html("<a href='#' onclick='edit(" + pos_id + ")'>编辑</a>&nbsp;|<a href='{:url('admin/Position/positionDel')}?pos_id="+pos_id+"'>删除</a>&nbsp;|<a href='{:url('admin/Position/positionInfo')}?pos_id="+pos_id+"'>详情</a>&nbsp;|<a href='#'>停用</a>");
                    }
                }
            })
        }
        function enable_ajax(pos_id, pos_status) {
            $.ajax({
                type: 'POST',
                url: "{:url('admin/Position/positionEnable')}",
                data: {
                    pos_id: pos_id,
                    pos_status: pos_status
                },
                datatype: 'JSON',
                success: function(data){
                    if (1 == data) {
                        window.location.reload();
                    }
                },
                error:function(){
                    alert("Wrong!")
                }
            })
        }
    </script>
</head>
<body marginwidth="0" marginheight="0">
<div class="container">
    <div class="public-nav">您当前的位置：<a href="#">管理首页</a>><a href="{:url('admin/Position/positionList')}">推荐位管理</a></div>
    <div class="public-content">
        <div class="public-content-header">
            <h3>查看商品列表<a href="{:url('admin/Position/positionAdd')}"><input type="button"  style="float:right;    margin-right: 17px;" value="新增推荐位数据"></a></h3>
        </div>
        <div class="public-content-cont">
            <table class="public-cont-table">
                <tr>
                    <!--<th style="width:5%">选择</th>-->
                    <th style="background-color: #c9dae4">ID</th>
                    <th style="background-color: #c9dae4">推荐位名称</th>
                    <th style="background-color: #c9dae4">推荐位描述</th>
                    <th style="background-color: #c9dae4">该推荐位商品总数</th>
                    <th style="background-color: #c9dae4">最后插入数据的时间</th>
                    <th style="background-color: #c9dae4">操作</th>
                </tr>
                {volist name="pos_list" id="pos"}
                <tr>
                    <!--<td><input type="checkbox"></td>-->
                    <td>{$pos.pos_id}</td>
                    <td><div id="name_{$pos.pos_id}">{$pos.pos_name}</div></td>
                    <td><div id="des_{$pos.pos_id}">{$pos.pos_description}</div></td>
                    <td>{$pos.pos_count}</td>
                    <td>{$pos.pos_last_time}</td>
                    <td><div id="but_{$pos.pos_id}"><a href="#" onclick='edit("{$pos.pos_id}")'>编辑</a>&nbsp;|<a href="{:url('admin/Position/positionDel')}?pos_id={$pos.pos_id}">删除</a>&nbsp;|<a href="{:url('admin/Position/positionInfo')}?pos_id={$pos.pos_id}">详情</a>&nbsp;|<a href="#" onclick='enable_ajax("{$pos.pos_id}","{$pos.status}")'>{$pos.status == 1?  '已启用(点击停用)' :'<i style="color: red">已停用(点击启用)</i>'}</a></div></td>
                </tr>
                {/volist}

            </table>
            <div class="page">

            </div>
        </div>
    </div>
</div>
</body>
</html>